package Twx0428;

import java.util.Scanner;

public class User {
        String userName;
        String password;
        int age;
        String phone;
        String address;
        boolean isLogin;
        int score;

    public User(String name,String pwd,boolean code) {
        userName = name;
        password = pwd;
        isLogin = code;
    }

    public User(){

    }

    public void showInfo() {
            System.out.println("账号：" + userName);
            System.out.println("密码：" + password);
            System.out.println("年龄：" + age);
            System.out.println("电话：" + phone);
            System.out.println("地址：" + address);
            System.out.println("是否在线：" + isLogin);
            System.out.println("积分：" + score);
        }
        // 密码尝试次数
        int pwdCount = 5;
        public int login(String pwdIn) {
            if (pwdCount == 0) {
                System.out.println("密码错误次数过多，已被锁定");
                return 2;
            }
            if (pwdIn.equals(password)) {
                if (isLogin) {
                    System.out.println(userName + "已在线，请勿重复登录操作");
                    return 0;
                }
                isLogin = true;
                score += 100;
                System.out.println(userName + "登录成功~ 积分增加了100分，现在的积分是：" +
                        score);
                pwdCount = 5;
                return 1;
            } else {
                System.out.println(userName + "密码输入错误~ 再输错" + pwdCount + "次，账号就会进入锁定~");
                pwdCount--;
                return 2;
            }
        }


        public void change(){
            Scanner sc=new Scanner(System.in);
            boolean isChange = false;
            while (true){
                System.out.println("选择要修改的内容：1.密码 \n 2.年龄 \n 3.电话 \n 4.地址 \n 0.退出");
                int ch = sc.nextInt();
                switch (ch){
                    case 1:
                        System.out.println("请输入新的密码：");
                        String newPassworld;
                        boolean isEqual = false;
                        while (true){
                            newPassworld = sc.next();
                            if (newPassworld.equals(password)){
                                System.out.println("新密码不能与旧密码相同！");
                                System.out.println("请输入新的密码：");
                            }else {
                                password = newPassworld;
                                if (!isEqual) break;
                            }
                        }
                        break;
                    case 2:
                        System.out.println("请输入新的年龄：");
                        age = sc.nextInt();
                        break;
                    case 3:
                        System.out.println("请输入新的电话：");
                        phone = sc.next();
                        break;
                    case 4:
                        System.out.println("请输入新的地址：");
                        address = sc.next();
                        break;
                    case 0:
                        isChange = true;
                }
                if (isChange) break;
            }
        }

        int isExit = 0;
        public void exit(){
            Scanner sc=new Scanner(System.in);
            System.out.println("确定要退出登录吗？\n 1.确定 \n 0.取消");
            isExit = sc.nextInt();
            if (isExit == 1){
                isLogin = false;
            }else {
                return;
            }
        }

        public int regist(){

            return 0;
        }

    public static void main(String[] args) {
    // 创建第一个User对象
        User user1 = new User();
        user1.userName = "testUser1";
        user1.password = "123";
        user1.age = 25;
        user1.phone = "123-456-7890";
        user1.address = "123 Test Street";
        user1.isLogin = false;
        user1.score = 100;
        user1.showInfo();
        user1.change();
        user1.exit();
        user1.showInfo();
    }
}

